#pragma once
#include <cstdio>
#include <iostream>
#include <string>
#include <ctime>
#include <unistd.h>
#include <sys/types.h>
#include <stdarg.h>
using namespace std;
enum
{
    Warning=0,
    Information,
    Debug,
    Error,
    Fatal,
    Unknown
};

string Get_Time()
{
    time_t now = std::time(nullptr);  
    return ctime(&now); 
}

string Log_Level(int level)
{
    switch (level)
    {
    case 0:
        return "Warning";
        break;
    case 1:
         return "Information";
         break;
    case 2:
        return "Debug";
        break;
    case 3:
        return "Error";
    case 4:
        return "Fatal";
        break;
    case 5:
    default:
        return "Unknown";
        break;
    }
}



//错误等级，时间，pid，消息体
void LogMessage(int level,const char* format...)
{
    char left[1024];
    char right[1024];
    string happentime=Get_Time();
    happentime.erase(happentime.size()-1,1);
    string loglevel=Log_Level(level);
    snprintf(left,1024,"日志等级为:%s,发生时间为:%s,进程pid为:%d,消息:",loglevel.c_str(),happentime.c_str(),getpid());
    va_list v;//char*
    va_start(v,format);//v指向可变参数的开始部分
    vsnprintf(right,1024,format,v);
    va_end(v);

    cout<<left<<right<<endl;
}